package com.chahu.vo;

import com.chahu.common.AppExceptionCodeMsg;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {

    private int code = 200;

    private String msg = "success";

    private T data;

    public static <T> Result success(T data){
        return new Result<>(200, "success", data);
    }

//    public static <T> Result success(String msg, T data){
//        return new Result<>(200, msg, data);
//    }

    public static <T> Result error(AppExceptionCodeMsg appExceptionCodeMsg){
        Result result = new Result<>(appExceptionCodeMsg.getCode(),
                appExceptionCodeMsg.getMsg(), null);
        return result;
    }

    public static <T> Result error(int code, String msg){
        return new Result<>(code, msg, null);
    }
}